//
//  LandInfoViewController.m
//  i读
//
//  Created by 123 on 15/10/19.
//  Copyright © 2015年 123. All rights reserved.
//


#import "LandInfoViewController.h"
//#import "findCodeViewController.h"
#import "LandViewController.h"
//#import "ViewController.h"
//#import "RequestManager.h"
//#import "SVProgressHUD.h"
//#import "AppPreference.h"
//#import "AppDelegate.h"
//#import "UserModel.h"
//#import <ShareSDK/ShareSDK.h>
//#import "RegisterViewController.h"
//#import <TencentOpenAPI/QQApiInterface.h>
//#import <WXApi.h>

@interface LandInfoViewController ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UILabel *QQLabel;
@property (weak, nonatomic) IBOutlet UIButton *QQLoginBtn;
@property (weak, nonatomic) IBOutlet UIButton *WeCharBtn;
@property (weak, nonatomic) IBOutlet UILabel *WeCharLabel;
@property (nonatomic ,strong)NSMutableArray *QQInfoArray;

@end

@implementation LandInfoViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.QQInfoArray = [NSMutableArray array];
    NSLog(@"");
    //占字符颜色设置
    [_CodeField setValue:[[UIColor whiteColor] colorWithAlphaComponent:0.7] forKeyPath:@"_placeholderLabel.textColor"];
    [_UsernameField setValue:[[UIColor whiteColor] colorWithAlphaComponent:0.7] forKeyPath:@"_placeholderLabel.textColor"];
    //占字符字体大小设置
    [_UsernameField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
    [_CodeField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
    //密码特殊形式显示
    _CodeField.secureTextEntry = YES;
    _CodeField.delegate = self;
    _UsernameField.delegate = self;
    [self.view endEditing:YES];
    
    //判断手机上是否安装QQ，若未安装，则隐藏QQ第三方登录按钮
//    if (![QQApiInterface isQQInstalled]) {
//        _QQLoginBtn.hidden = YES;
//        _QQLabel.hidden = YES;
//    }
//    else{
        [_QQLoginBtn addTarget:self action:@selector(QQLogin:) forControlEvents:UIControlEventTouchUpInside];
//    }
    
    //判断手机上是否安装微信，若未安装，则隐藏微信第三方登录按钮
//    if (![WXApi isWXAppInstalled]) {
//        _WeCharBtn.hidden = YES;
//        _WeCharLabel.hidden = YES;
//    }
    
    [_WeCharBtn addTarget:self action:@selector(WeChatLogin:) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -         ---------点击响应事件

//返回
- (IBAction)backBtn:(UIButton *)sender {
    NSArray *arr = self.navigationController.viewControllers;
    
    for ( int i = 0; i<arr.count; i++) {
        if ([arr[i] isKindOfClass:[LandViewController class]]) {
            [self.navigationController popToViewController:arr[i] animated:YES];
            break;
        }
   }
    
}


//登录

//- (IBAction)commitBtn:(UIButton *)sender {
//    //判断账号密码若为空则提示
//    if ([self.UsernameField.text isEqualToString:@""]) {
//        if ([[NSThread currentThread] isMainThread]) {
//            NSLog(@"YES");
//        }
//        [SVProgressHUD showErrorWithStatus:@"请输入账号" maskType:SVProgressHUDMaskTypeBlack];
//    }else if([self.CodeField.text isEqualToString:@""]){
//        [SVProgressHUD showErrorWithStatus:@"请输入密码" maskType:SVProgressHUDMaskTypeBlack];
//    }else{
//        
//        /****接口****/
//        [RequestManager loginWithPhone:self.UsernameField.text
//                                pwd:self.CodeField.text
//                  completionHandler:^(UserModel *userInfo, NSString *reCode, NSString *reMsg) {
//                     if ([reCode isEqualToString:@"0"]) {
//                         ViewController *view = [[ViewController alloc]init];
//                       
//                          //存储用户数据
//                          [[AppPreference defaultPreference]loginWithUser:userInfo];
//                          [AppPreference defaultPreference].isLogin = YES;
//                          [AppPreference defaultPreference].autoLogin = YES;
//                          [AppPreference defaultPreference].currentUserId = [NSString stringWithFormat:@"%ld",(long)userInfo.userId];
//                          [AppPreference defaultPreference].currentPhone = userInfo.phone;
//                          
//                       
//                          [self.navigationController pushViewController:view animated:YES];
//                          
//                      }
//                  }];
//    }
//
//}
//
////QQ登录 （第三方）
//- (void)QQLogin:(UIButton *)sender {
//    
//    [ShareSDK getUserInfo:SSDKPlatformTypeQQ onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
//        if (state == SSDKResponseStateSuccess)
//        {
//            [self.QQInfoArray addObject:user.uid];
//            [_QQInfoArray addObject:user.nickname];
//            [_QQInfoArray addObject:user.icon];
//            
//            [RequestManager thridLoginWithThirdId: user.uid thirdType:@"0" completionHandler:^(UserModel *userInfo,NSString *reCode,NSString *reMsg){
//                if ([reCode isEqualToString:@"0"]) {
//                    
//                    /****接口****/
//                    ViewController *view = [[ViewController alloc]init];
//                    
//                    //存储用户数据
//                    [[AppPreference defaultPreference]loginWithUser:userInfo];
//                    [AppPreference defaultPreference].isLogin = YES;
//                    [AppPreference defaultPreference].autoLogin = YES;
//                    [AppPreference defaultPreference].currentUserId = [NSString stringWithFormat:@"%ld",(long)userInfo.userId];
//                    [AppPreference defaultPreference].currentPhone = userInfo.phone;
//                    view.target = userInfo.target;
//                    
//                    [self.navigationController pushViewController:view animated:YES];
//                }
//                else if ([reCode isEqualToString:@"2"]) {
//                    RegisterViewController *registerView = [[RegisterViewController alloc]init];
//                    registerView.QQInfoArr = _QQInfoArray;
//                    registerView.type = @"0";
//                    [self.navigationController pushViewController:registerView animated:YES];
//                }
//                else{
//                    NSLog(@"%@",reMsg);
//                }
//            }];
//        }
//        else if(state == SSDKResponseStateFail)
//        {
//            NSLog(@"error:%@",error);
//        }
//    }];
//    
//}
//
////新浪微博登录（第三方）
//- (IBAction)WeiBOLogin:(UIButton *)sender{
//    
//    [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
//        if (state == SSDKResponseStateSuccess)
//        {
//            if (state == SSDKResponseStateSuccess)
//            {
//                [self.QQInfoArray addObject:user.uid];
//                [_QQInfoArray addObject:user.nickname];
//                [_QQInfoArray addObject:user.icon];
//                
//                [RequestManager thridLoginWithThirdId: user.uid thirdType:@"1" completionHandler:^(UserModel *userInfo,NSString *reCode,NSString *reMsg){
//                    if ([reCode isEqualToString:@"0"]) {
//                        
//                        /****接口****/
//                        ViewController *view = [[ViewController alloc]init];
//                        
//                        //存储用户数据
//                        [[AppPreference defaultPreference]loginWithUser:userInfo];
//                        [AppPreference defaultPreference].isLogin = YES;
//                        [AppPreference defaultPreference].autoLogin = YES;
//                        [AppPreference defaultPreference].currentUserId = [NSString stringWithFormat:@"%ld",(long)userInfo.userId];
//                        [AppPreference defaultPreference].currentPhone = userInfo.phone;
//                        view.target = userInfo.target;
//                        
//                        [self.navigationController pushViewController:view animated:YES];
//                    }
//                    else if ([reCode isEqualToString:@"2"]) {
//                        RegisterViewController *registerView = [[RegisterViewController alloc]init];
//                        registerView.QQInfoArr = _QQInfoArray;
//                        registerView.type = @"1";
//                        [self.navigationController pushViewController:registerView animated:YES];
//                    }
//                    else{
//                        NSLog(@"%@",reMsg);
//                    }
//                }];
//            }
//            else if(state == SSDKResponseStateFail)
//            {
//                NSLog(@"error:%@",error);
//            }
//            
//        }
//    }];
//}
//
////微信登陆（第三方）
//- (void)WeChatLogin:(UIButton *)sender{
//
//    [ShareSDK getUserInfo:SSDKPlatformTypeWechat onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
//        if (state == SSDKResponseStateSuccess)
//        {
//            if (state == SSDKResponseStateSuccess)
//            {
//                [self.QQInfoArray addObject:user.uid];
//                [_QQInfoArray addObject:user.nickname];
//                [_QQInfoArray addObject:user.icon];
//                
//                [RequestManager thridLoginWithThirdId: user.uid thirdType:@"2" completionHandler:^(UserModel *userInfo,NSString *reCode,NSString *reMsg){
//                    if ([reCode isEqualToString:@"0"]) {
//                        
//                        /****接口****/
//                        ViewController *view = [[ViewController alloc]init];
//                        
//                        //存储用户数据
//                        [[AppPreference defaultPreference]loginWithUser:userInfo];
//                        [AppPreference defaultPreference].isLogin = YES;
//                        [AppPreference defaultPreference].autoLogin = YES;
//                        [AppPreference defaultPreference].currentUserId = [NSString stringWithFormat:@"%ld",(long)userInfo.userId];
//                        [AppPreference defaultPreference].currentPhone = userInfo.phone;
//                        view.target = userInfo.target;
//                        
//                        [self.navigationController pushViewController:view animated:YES];
//                    }
//                    else if ([reCode isEqualToString:@"2"]) {
//                        RegisterViewController *registerView = [[RegisterViewController alloc]init];
//                        registerView.QQInfoArr = _QQInfoArray;
//                        registerView.type = @"2";
//                        [self.navigationController pushViewController:registerView animated:YES];
//                    }
//                    else{
//                        NSLog(@"%@",reMsg);
//                    }
//                }];
//            }
//            else if(state == SSDKResponseStateFail)
//            {
//                NSLog(@"error:%@",error);
//            }
//
//        }
//
//    }];
//
//}

#pragma  mark -         ------- 取消键盘响应

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    UITouch *touch = [touches anyObject];
    
    if (![touch.view isKindOfClass: [UITextField class]] || ![touch.view isKindOfClass: [UITextView class]]) {
        
        [self.view endEditing:YES];
        
    }
    
}


@end
